---
title: "Howe, Philip J., Steinecke, David & Zuber, Christina Isabel (2024). Competing Principals in a Multinational State: Legislative Behavior in Imperial Austria, 1907-1914."
output: html_notebook
---

```{r setup}
library(tidyverse)
library(glue)
library(janitor)
library(readxl)
library(haven)
library(lme4)
library(texreg)
library(ggtext)
library(ggeffects)
```


# Dyadic analysis

```{r}
load("dyadic_analysis_session_yn.RData")
```


## Empty models

```{r}
# Pooled Empty Model
mod_empty <- lmer(share_vote_same ~ 
                    (1|dyad_id) +
                    (1|rep_id) +
                    (1|rep_id_2),
                  data = dyadic_analysis_session_yn,
                  control = lmerControl(optimizer = "bobyqa", 
                                        optCtrl = list(maxfun = 2e9)))

summary(mod_empty)
save(mod_empty, file = "models/mod_empty.RData")

# Empty Model 1907-1911
mod_empty_1907 <- lmer(share_vote_same ~ 
                         (1|dyad_id) +
                         (1|rep_id) +
                         (1|rep_id_2),
                       data = dyadic_analysis_session_yn %>% 
                         filter(legislature == 1907),
                       control = lmerControl(optimizer = "bobyqa", 
                                             optCtrl = list(maxfun = 2e9)))

summary(mod_empty_1907)
save(mod_empty_1907, file = "models/mod_empty_1907.RData")

# Empty Model 1911-1914
mod_empty_1911 <- lmer(share_vote_same ~ 
                         (1|dyad_id) +
                         (1|rep_id) +
                         (1|rep_id_2),
                       data = dyadic_analysis_session_yn %>% 
                         filter(legislature == 1911),
                       control = lmerControl(optimizer = "bobyqa", 
                                             optCtrl = list(maxfun = 2e9)))

summary(mod_empty_1911)
save(mod_empty_1911, file = "models/mod_empty_1911.RData")
```


## Calculating ICCs for empty models

```{r}
#performance::icc(mod_empty)
#performance::icc(mod_empty_1907)
#performance::icc(mod_empty_1911)

# Extract variance components
var_components <- VarCorr(mod_empty) # mod_empty_1907 or mod_empty_1911

# Variance components for random intercepts
var_dyad <- var_components$dyad_id[[1]]   # Variance of dyad_id
var_rep1 <- var_components$rep_id[[1]]   # Variance of rep_id
var_rep2 <- var_components$rep_id_2[[1]] # Variance of rep_id_2

# Residual variance
var_residual <- sigma(mod_empty)^2 # mod_empty_1907 or mod_empty_1911

# Total variance
total_variance <- var_dyad + var_rep1 + var_rep2 + var_residual

# Calculate ICC for the null model
ICC <- (var_dyad + var_rep1 + var_rep2) / total_variance

ICC
```

mod_empty: [1] 0.3865307
mod_empty_1907: [1] 0.3445596
mod_empty_1911: [1] 0.5537348



## Models predicting legislators’ voting similarity including umbrella organizations

```{r}
# Pooled Model
mod_yn_max <- lmer(share_vote_same ~ klub_max_same + 
                     partylabel_same + 
                     verein_same +
                     ideology_unclear_same +
                     largest_lang_gr_same +
                     dom_sec_same +
                     region_same +
                     (1|dyad_id) +
                     (1|rep_id) +
                     (1|rep_id_2),
                   data = dyadic_analysis_session_yn,
                   control = lmerControl(optimizer = "bobyqa", 
                                         optCtrl = list(maxfun = 2e9)))

summary(mod_yn_max)
save(mod_yn_max, file = "models/mod_yn_max.RData")

# Model 1907-1911
mod_yn_1907_max <- lmer(share_vote_same ~ klub_max_same + 
                          partylabel_same + 
                          verein_same +
                          ideology_unclear_same +
                          largest_lang_gr_same +
                          dom_sec_same +
                          region_same +
                          (1|dyad_id) +
                          (1|rep_id) +
                          (1|rep_id_2),
                        data = dyadic_analysis_session_yn %>% 
                          filter(legislature == 1907),
                        control = lmerControl(optimizer = "bobyqa", 
                                              optCtrl = list(maxfun = 2e9)))

summary(mod_yn_1907_max)
save(mod_yn_1907_max, file = "models/mod_yn_1907_max.RData")

# Model 1911-1914
mod_yn_1911_max <- lmer(share_vote_same ~ klub_max_same + 
                          partylabel_same + 
                          verein_same +
                          ideology_unclear_same +
                          largest_lang_gr_same +
                          dom_sec_same +
                          region_same +
                          (1|dyad_id) +
                          (1|rep_id) +
                          (1|rep_id_2),
                        data = dyadic_analysis_session_yn %>% 
                          filter(legislature == 1911),
                        control = lmerControl(optimizer = "bobyqa", 
                                              optCtrl = list(maxfun = 2e9)))

summary(mod_yn_1911_max)
save(mod_yn_1911_max, file = "models/mod_yn_1911_max.RData")
```


## Models predicting legislators’ voting similarity excluding umbrella organizations

```{r}
# Pooled Model
mod_yn_min <- lmer(share_vote_same ~ klub_min_same + 
                     partylabel_same + 
                     verein_same +
                     ideology_unclear_same +
                     largest_lang_gr_same +
                     dom_sec_same +
                     region_same +
                     (1|dyad_id) +
                     (1|rep_id) +
                     (1|rep_id_2),
                   data = dyadic_analysis_session_yn,
                   control = lmerControl(optimizer = "bobyqa", 
                                         optCtrl = list(maxfun = 2e9)))

summary(mod_yn_min)
save(mod_yn_min, file = "models/mod_yn_min.RData")

# Model 1907-1911
mod_yn_1907_min <- lmer(share_vote_same ~ klub_min_same + 
                          partylabel_same + 
                          verein_same +
                          ideology_unclear_same +
                          largest_lang_gr_same +
                          dom_sec_same +
                          region_same +
                          (1|dyad_id) +
                          (1|rep_id) +
                          (1|rep_id_2),
                        data = dyadic_analysis_session_yn %>% 
                          filter(legislature == 1907),
                        control = lmerControl(optimizer = "bobyqa", 
                                              optCtrl = list(maxfun = 2e9)))

summary(mod_yn_1907_min)
save(mod_yn_1907_min, file = "models/mod_yn_1907_min.RData")

# Model 1911-1914
mod_yn_1911_min <- lmer(share_vote_same ~ klub_min_same + 
                          partylabel_same + 
                          verein_same +
                          ideology_unclear_same +
                          largest_lang_gr_same +
                          dom_sec_same +
                          region_same +
                          (1|dyad_id) +
                          (1|rep_id) +
                          (1|rep_id_2),
                        data = dyadic_analysis_session_yn %>% 
                          filter(legislature == 1911),
                        control = lmerControl(optimizer = "bobyqa", 
                                              optCtrl = list(maxfun = 2e9)))

summary(mod_yn_1911_min)
save(mod_yn_1911_min, file = "models/mod_yn_1911_min.RData")
```


## Figure 2 - Average Marginal Predicted Probabilities from the Dyadic Analysis Using Linear Multilevel Regression with Three Crossed Random Effects

```{r}
pr_yn_max_klub <- predict_response(mod_yn_max, "klub_max_same [0,1]", margin = "empirical") %>% 
  tibble() %>% 
  mutate(coeff = "Club",
         term = "Pooled Model")
pr_yn_max_party <- predict_response(mod_yn_max, "partylabel_same [0,1]", margin = "empirical") %>% 
  tibble() %>% 
  mutate(coeff = "Party",
         term = "Pooled Model")
pr_yn_1907_max_klub <- predict_response(mod_yn_1907_max, "klub_max_same [0,1]", margin = "empirical") %>% 
  tibble() %>% 
  mutate(coeff = "Club",
         term = "1907-11")
pr_yn_1907_max_party <- predict_response(mod_yn_1907_max, "partylabel_same [0,1]", margin = "empirical") %>% 
  tibble() %>% 
  mutate(coeff = "Party",
         term = "1907-11")
pr_yn_1911_max_klub <- predict_response(mod_yn_1911_max, "klub_max_same [0,1]", margin = "empirical") %>% 
  tibble() %>% 
  mutate(coeff = "Club",
         term = "1911-14")
pr_yn_1911_max_party <- predict_response(mod_yn_1911_max, "partylabel_same [0,1]", margin = "empirical") %>% 
  tibble() %>% 
  mutate(coeff = "Party",
         term = "1911-14")

pr_yn_max_plot <- bind_rows(pr_yn_max_klub, pr_yn_max_party, pr_yn_1907_max_klub,
                            pr_yn_1907_max_party, pr_yn_1911_max_klub, pr_yn_1911_max_party) %>% 
  mutate(term = term %>% factor(levels = c('Pooled Model','1907-11','1911-14')))

pr_yn_max_pred <- pr_yn_max_plot %>% 
  pivot_wider(names_from = x,
              values_from = predicted:conf.high) %>% 
  mutate(dif = predicted_1 - predicted_0,
         across(predicted_0:dif, ~ round(.x * 100, digits = 2)))

ggplot(pr_yn_max_plot, aes(x = x %>% as.character(), y = predicted, 
                           ymin = conf.low, ymax = conf.high, colour = term, 
                           group = interaction(term, coeff))) +
  geom_point(size = 3, position = position_dodge(width = 0.5)) +
  geom_errorbar(width = 0.2, position = position_dodge(width = 0.5)) +
  geom_line(position = position_dodge(width = 0.5)) +
  geom_blank(aes(ymin = 0.45, 
                 ymax = 0.8)) +
  facet_wrap(~ coeff, 
             ncol = 4,
             labeller = labeller(coeff = str_to_title)) + 
  scale_x_discrete(labels = c("0" = "Different", "1" = "Same")) + 
  scale_y_continuous(labels = scales::percent) +
  scale_colour_grey() +
  ylab("Predicted Probability of Casting the Same Vote") +
  xlab("") +
  labs(caption = "<i>Note:</i> This figure displays average predicted probabilities at observed values from a dyadic 
  analysis, where observations represent unique pairwise comparisons between MPs. 
  The dependent variable measures the proportion of votes on which legislators 
  within a dyad agree, while the independent variables capture similarities and 
  differences in legislators' traits. The bars are 95% Confidence Intervals.
  For the detailed regression results, see <b>Appendix E - Table 1</b>.<br>
  Pooled model: AIC = 621940.76, BIC = 622080.54, Log Likelihood = -310958.38, 
  845638 observations/166012 dyads/623 legislators.<br>
  Model 1907-11: AIC = 485460.61, BIC = 485595.54, Log Likelihood = -242718.30, 
  564794 observations/107911 dyads/467 legislators.<br>
  Model 1911-14: AIC = 123716.47, BIC = 123843.02, Log Likelihood = -61846.24, 
  280844 observations/100635 dyads/449 legislators.") + 
  theme_bw() +
  theme(text = element_text(family = "serif"),
        strip.text = element_text(size = 16),
        axis.title.y = element_text(size = 14),
        axis.text = element_text(size = 12), 
        legend.title = element_text(size = 14),
        legend.text = element_text(size = 14),
        plot.caption = element_textbox_simple(size = 10, width = unit(1.1, "npc"), 
                                              margin = margin(10, 10, 10, -10))) +
  guides(colour = guide_legend(title = "Term", position = "bottom"))

ggsave("figures/figure_2.jpeg", width = 20, height = 20, units = "cm", dpi = 800)
```


## Appendix E – Detailed Regression Results, Tables 1 & 2

```{r}
wordreg(l = list(mod_yn_max, mod_yn_1907_max, mod_yn_1911_max),
        file = "tables/appendix_e_table_1.doc",
        custom.model.names = c("Pooled Model", "1907 - 1911", "1911 - 1914"),
        custom.coef.map = list("klub_max_same" = "Same Club",
                               "partylabel_same" = "Same Party", 
                               "verein_same" = "Same Association", 
                               "ideology_unclear_same" = "Same Ideology", 
                               "largest_lang_gr_same" = "Same National Identity",
                               "dom_sec_same" = "Same Economic sector", 
                               "region_same" = "Same Region", 
                               "(Intercept)" = "Intercept"),
        groups = list("Fixed Effects" = 1:8),
        custom.gof.names = c(NA, NA, NA, "Number of Observations", 
                             "Number of Dyads", "Number of Legislators 1", 
                             "Number of Legislators 2", 
                             "Variance Intercept Dyad", "Variance Intercept Legislator 1", 
                             "Variance Intercept Legislator 2", "Variance Residual"),
        custom.gof.rows = list("Random Effects" = c("", "", "")),
        reorder.gof = c(1, 10, 11, 9, 12, 2, 3, 4, 7, 8, 6, 5),
        single.row = TRUE)

wordreg(l = list(mod_yn_min, mod_yn_1907_min, mod_yn_1911_min),
        file = "tables/appendix_e_table_2.doc",
        custom.model.names = c("Pooled Model", "1907 - 1911", "1911 - 1914"),
        custom.coef.map = list("klub_min_same" = "Same Club",
                               "partylabel_same" = "Same Party", 
                               "verein_same" = "Same Association", 
                               "ideology_unclear_same" = "Same Ideology", 
                               "largest_lang_gr_same" = "Same National Identity",
                               "dom_sec_same" = "Same Economic sector", 
                               "region_same" = "Same Region", 
                               "(Intercept)" = "Intercept"),
        groups = list("Fixed Effects" = 1:8),
        custom.gof.names = c(NA, NA, NA, "Number of Observations", 
                             "Number of Dyads", "Number of Legislators 1", 
                             "Number of Legislators 2", 
                             "Variance Intercept Dyad", "Variance Intercept Legislator 1", 
                             "Variance Intercept Legislator 2", "Variance Residual"),
        custom.gof.rows = list("Random Effects" = c("", "", "")),
        reorder.gof = c(1, 10, 11, 9, 12, 2, 3, 4, 7, 8, 6, 5),
        single.row = TRUE)
```



# Deviation analysis from club including umbrella organizations

```{r}
load("dev_analysis_group_max.RData")
```


## Empty models

```{r}
# Empty Model 1907-1911
mod_dev_07_max_empty <- glmer(dev_group ~  
                                (1|rcv) +
                                (1|rep_id), 
                              data = dev_analysis_group_max %>% 
                                filter(legislature == 1907), 
                              family = binomial(link = "logit"),
                              control = glmerControl(optimizer = "bobyqa", 
                                                     optCtrl = list(maxfun = 2e9)))

summary(mod_dev_07_max_empty)
save(mod_dev_07_max_empty, file = "models/mod_dev_07_max_empty.RData")

# Empty Model 1911-1914
mod_dev_11_max_empty <- glmer(dev_group ~  
                                (1|rcv) +
                                (1|rep_id), 
                              data = dev_analysis_group_max %>% 
                                filter(legislature == 1911), 
                              family = binomial(link = "logit"),
                              control = glmerControl(optimizer = "bobyqa", 
                                                     optCtrl = list(maxfun = 2e9)))

summary(mod_dev_11_max_empty)
save(mod_dev_11_max_empty, file = "models/mod_dev_11_max_empty.RData")
```


## Calculating ICCs for empty models

```{r}
performance::icc(mod_dev_07_max_empty) # set by_group = TRUE for specific group-levels
performance::icc(mod_dev_11_max_empty)
```

mod_dev_07_max_empty: 0.652
mod_dev_11_max_empty: 0.610



## Analysis of legislators’ deviation in roll call votes from their club vote including umbrella organizations

```{r}
# Combined Model 1907-1911
mod_dev_07_max <- glmer(dev_group ~ dev_language +
                          dev_sector + 
                          max_vote_share +
                          dev_ideology +
                          dev_assoc +
                          (1|rcv) +
                          (1|rep_id), 
                        data = dev_analysis_group_max %>% 
                          filter(legislature == 1907), 
                        family = binomial(link = "logit"),
                        control = glmerControl(optimizer = "bobyqa", 
                                               optCtrl = list(maxfun = 2e9)))

summary(mod_dev_07_max)
save(mod_dev_07_max, file = "models/mod_dev_07_max.RData")

# District principal model 1907-1911
mod_dev_07_dist_max <- glmer(dev_group ~ dev_language +
                               dev_sector +
                               max_vote_share +
                               (1|rcv) +
                               (1|rep_id), 
                             data = dev_analysis_group_max %>% 
                               filter(legislature == 1907), 
                             family = binomial(link = "logit"),
                             control = glmerControl(optimizer = "bobyqa", 
                                                    optCtrl = list(maxfun = 2e9)))

summary(mod_dev_07_dist_max)
save(mod_dev_07_dist_max, file = "models/mod_dev_07_dist_max.RData")

# Ideological heterogeneity model 1907-1911
mod_dev_07_id_max <- glmer(dev_group ~ dev_ideology +
                             (1|rcv) +
                             (1|rep_id), 
                           data = dev_analysis_group_max %>% 
                             filter(legislature == 1907), 
                           family = binomial(link = "logit"),
                           control = glmerControl(optimizer = "bobyqa", 
                                                  optCtrl = list(maxfun = 2e9)))

summary(mod_dev_07_id_max)
save(mod_dev_07_id_max, file = "models/mod_dev_07_id_max.RData")

# Functional principal model 1907-1911
mod_dev_07_func_max <- glmer(dev_group ~ dev_assoc +
                               (1|rcv) +
                               (1|rep_id), 
                             data = dev_analysis_group_max %>% 
                               filter(legislature == 1907), 
                             family = binomial(link = "logit"),
                             control = glmerControl(optimizer = "bobyqa", 
                                                    optCtrl = list(maxfun = 2e9)))

summary(mod_dev_07_func_max)
save(mod_dev_07_func_max, file = "models/mod_dev_07_func_max.RData")

# Combined model 1911-1914
mod_dev_11_max <- glmer(dev_group ~ dev_language +
                          dev_sector + 
                          max_vote_share +
                          dev_ideology +
                          dev_assoc +
                          (1|rcv) +
                          (1|rep_id), 
                        data = dev_analysis_group_max %>% 
                          filter(legislature == 1911), 
                        family = binomial(link = "logit"),
                        control = glmerControl(optimizer = "bobyqa", 
                                               optCtrl = list(maxfun = 2e9)))

summary(mod_dev_11_max)
save(mod_dev_11_max, file = "models/mod_dev_11_max.RData")

# District principal model 1911-1914
mod_dev_11_dist_max <- glmer(dev_group ~ dev_language +
                               dev_sector +
                               max_vote_share +
                               (1|rcv) +
                               (1|rep_id), 
                             data = dev_analysis_group_max %>% 
                               filter(legislature == 1911), 
                             family = binomial(link = "logit"),
                             control = glmerControl(optimizer = "bobyqa", 
                                                    optCtrl = list(maxfun = 2e9)))

summary(mod_dev_11_dist_max)
save(mod_dev_11_dist_max, file = "models/mod_dev_11_dist_max.RData")

# Ideological heterogeneity model 1911-1914
mod_dev_11_id_max <- glmer(dev_group ~ dev_ideology +
                             (1|rcv) +
                             (1|rep_id), 
                           data = dev_analysis_group_max %>% 
                             filter(legislature == 1911), 
                           family = binomial(link = "logit"),
                           control = glmerControl(optimizer = "bobyqa", 
                                                  optCtrl = list(maxfun = 2e9)))

summary(mod_dev_11_id_max)
save(mod_dev_11_id_max, file = "models/mod_dev_11_id_max.RData")

# Functional principal model 1911-1914
mod_dev_11_func_max <- glmer(dev_group ~ dev_assoc +
                               (1|rcv) +
                               (1|rep_id), 
                             data = dev_analysis_group_max %>% 
                               filter(legislature == 1911), 
                             family = binomial(link = "logit"),
                             control = glmerControl(optimizer = "bobyqa", 
                                                    optCtrl = list(maxfun = 2e9)))

summary(mod_dev_11_func_max)
save(mod_dev_11_func_max, file = "models/mod_dev_11_func_max.RData")
```


## Figure 4 - Average Marginal Predicted Probabilities from the Deviation Analysis Using Logistic Multilevel Regression with Two Crossed Random Effects

```{r}
pr_dev_07_max_lang <- predict_response(mod_dev_07_max, "dev_language [0,1]", margin = "empirical") %>%
  tibble() %>% 
  mutate(coeff = "National Identity",
         term = "1907-11")
pr_dev_07_max_sec <- predict_response(mod_dev_07_max, "dev_sector [0,1]", margin = "empirical") %>%
  tibble() %>% 
  mutate(coeff = "Economic Sector",
         term = "1907-11")
pr_dev_11_max_lang <- predict_response(mod_dev_11_max, "dev_language [0,1]", margin = "empirical") %>%
  tibble() %>% 
  mutate(coeff = "National Identity",
         term = "1911-14")
pr_dev_11_max_sec <- predict_response(mod_dev_11_max, "dev_sector [0,1]", margin = "empirical") %>%
  tibble() %>% 
  mutate(coeff = "Economic Sector",
         term = "1911-14")
pr_dev_07_max_comp <- predict_response(mod_dev_07_max, "max_vote_share [0.262935,0.387935,0.512935,0.637935,0.762935,0.887935,0.9994289]", margin = "empirical") %>% 
  tibble() %>% 
  mutate(coeff = "District Competitiveness",
         term = "1907-11")
pr_dev_07_max_ideo <- predict_response(mod_dev_07_max, "dev_ideology [0,1]", margin = "empirical") %>% 
  tibble() %>% 
  mutate(coeff = "Ideology",
         term = "1907-11")
pr_dev_07_max_assoc <- predict_response(mod_dev_07_max, "dev_assoc [0,1]", margin = "empirical") %>% 
  tibble() %>% 
  mutate(coeff = "Association Portfolio",
         term = "1907-11")
pr_dev_11_max_comp <- predict_response(mod_dev_11_max, "max_vote_share [0.262935,0.387935,0.512935,0.637935,0.762935,0.887935,0.9994289]", margin = "empirical") %>% 
  tibble() %>% 
  mutate(coeff = "District Competitiveness",
         term = "1911-14")
pr_dev_11_max_ideo <- predict_response(mod_dev_11_max, "dev_ideology [0,1]", margin = "empirical") %>% 
  tibble() %>% 
  mutate(coeff = "Ideology",
         term = "1911-14")
pr_dev_11_max_assoc <- predict_response(mod_dev_11_max, "dev_assoc [0,1]", margin = "empirical") %>% 
  tibble() %>% 
  mutate(coeff = "Association Portfolio",
         term = "1911-14")

pr_dev_max_plot <- bind_rows(pr_dev_07_max_lang, pr_dev_07_max_sec,
                             pr_dev_11_max_lang, pr_dev_11_max_sec)

pr_dev_max <- bind_rows(pr_dev_max_plot, pr_dev_07_max_ideo, pr_dev_07_max_assoc, 
                        pr_dev_11_max_ideo, pr_dev_11_max_assoc) %>% 
  pivot_wider(names_from = x,
              values_from = predicted:conf.high) %>% 
  mutate(dif = predicted_1 - predicted_0,
         across(predicted_0:dif, ~ round(.x * 100, digits = 2)))


ggplot(pr_dev_max_plot, aes(x = x %>% as.character(), y = predicted, 
                           ymin = conf.low, ymax = conf.high, colour = term, 
                           group = interaction(term, coeff))) +
  geom_point(size = 3, position = position_dodge(width = 0.4)) +
  geom_errorbar(width = 0.2, position = position_dodge(width = 0.4)) +
  geom_line(position = position_dodge(width = 0.4)) +
  geom_blank(aes(ymin = 0, ymax = 0.40)) +
  facet_wrap(~ coeff, 
             #scales = "free_y",
             labeller = labeller(coeff = str_to_title)) + 
  scale_x_discrete(labels = c("0" = "Same", "1" = "Different")) + 
  scale_y_continuous(labels = scales::percent) +
  scale_colour_grey() +
  ylab("Predicted Probability of Casting a Deviating Vote") +
  xlab("") +
  labs(caption = "<i>Note:</i> This figure displays the average predicted probabilities at observed values of legislators to deviate from their club's plurality vote in roll call votes. Club affiliation is operationalized using umbrella organizations where applicable. Economic Sector refers to MPs representing a district with a different dominant economic sector than the plurality of their club colleagues. National Identity refers to MPs representing a district with a different dominant language group than the plurality of their club colleagues. The bars are 95% Confidence Intervals. While the confidence intervals overlap, the underlying model coefficients are statistically significant. This discrepancy arises because predicted probabilities average over observed values of all other covariates, and their confidence intervals reflect this variation. For the detailed regression results, see <b>Appendix E - Table 3 and 4</b>.<br>
  Model 1907-11: AIC = 2583.30, BIC = 2720.22, Log Likelihood = -1272.65, 9957 observations/459 legislators/29 RCVs.<br>
  Model 1911-14: AIC = 4984.09, BIC = 5110.95, Log Likelihood = -2475.04, 12865 observations/435 legislators/41 RCVs.") + 
  theme_bw() +
  theme(text = element_text(family = "serif"),
        strip.text = element_text(size = 16),
        axis.title.y = element_text(size = 14),
        axis.text = element_text(size = 12), 
        legend.title = element_text(size = 14),
        legend.text = element_text(size = 14),
        plot.caption = element_textbox_simple(size = 10, width = unit(1, "npc"), 
                                              margin = margin(10, 10, 10, 10))) +
  guides(colour = guide_legend(title = "Term", position = "bottom"))
         
ggsave("figures/figure_4.jpeg", width = 20, height = 20, units = "cm", dpi = 800)
```


## Appendix E – Detailed Regression Results, Tables 3 - 4

```{r}
wordreg(l = list(mod_dev_07_dist_max,  mod_dev_07_id_max, 
                 mod_dev_07_func_max, mod_dev_07_max),
        file = "tables/appendix_e_table_3.doc",
        custom.model.names = c("District Principal Model", "Ideological Heterogeneity Model", 
                               "Functional Principal Model", "Combined Model"),
        custom.coef.map = list("dev_language" = "Different National Identity", 
                               "dev_sector" = "Different Economic Sector",
                               "max_vote_share" = "District Competitiveness",
                               "dev_ideology" = "Different Ideology",
                               "dev_assoc" = "Different Association Memberships",
                               "(Intercept)" = "Intercept"),
        groups = list("Fixed Effects \n District Principal" = 1:3, 
                      "Party Ideology" = 4:4, 
                      "Functional Principal" = 5:6),
        custom.gof.names = c(NA, NA, NA, "Number of Observations", 
                             "Number of Legislators", "Number of RCVs", 
                             "Variance Intercept Legislator", "Variance Intercept RCV"),
        custom.gof.rows = list("Random Effects" = c("", "", "", "")),
        reorder.gof = c(1, 9, 8, 2, 3, 4, 7, 6, 5),
        single.row = TRUE)

wordreg(l = list(mod_dev_11_dist_max,  mod_dev_11_id_max, 
                 mod_dev_11_func_max, mod_dev_11_max),
        file = "tables/appendix_e_table_4.doc",
        custom.model.names = c("District Principal Model", "Ideological Heterogeneity Model", 
                               "Functional Principal Model", "Combined Model"),
        custom.coef.map = list("dev_language" = "Different National Identity", 
                               "dev_sector" = "Different Economic Sector",
                               "max_vote_share" = "District Competitiveness",
                               "dev_ideology" = "Different Ideology",
                               "dev_assoc" = "Different Association Memberships",
                               "(Intercept)" = "Intercept"),
        groups = list("Fixed Effects \n District Principal" = 1:3, 
                      "Party Ideology" = 4:4, 
                      "Functional Principal" = 5:6),
        custom.gof.names = c(NA, NA, NA, "Number of Observations", 
                             "Number of Legislators", "Number of RCVs", 
                             "Variance Intercept Legislator", "Variance Intercept RCV"),
        custom.gof.rows = list("Random Effects" = c("", "", "", "")),
        reorder.gof = c(1, 9, 8, 2, 3, 4, 7, 6, 5),
        single.row = TRUE)
```



# Deviation analysis from club excluding umbrella organizations

```{r}
load(file = "dev_analysis_group_min.RData")
```


## Empty models

```{r}
# Empty Model 1907-1911
mod_dev_07_min_empty <- glmer(dev_group ~  
                                (1|rcv) +
                                (1|rep_id), 
                              data = dev_analysis_group_min %>% 
                                filter(legislature == 1907), 
                              family = binomial(link = "logit"),
                              control = glmerControl(optimizer = "bobyqa", 
                                                     optCtrl = list(maxfun = 2e9)))

summary(mod_dev_07_min_empty)
save(mod_dev_07_min_empty, file = "models/mod_dev_07_min_empty.RData")

# Empty Model 1911-1914
mod_dev_11_min_empty <- glmer(dev_group ~  
                                (1|rcv) +
                                (1|rep_id), 
                              data = dev_analysis_group_min %>% 
                                filter(legislature == 1911), 
                              family = binomial(link = "logit"),
                              control = glmerControl(optimizer = "bobyqa", 
                                                     optCtrl = list(maxfun = 2e9)))

summary(mod_dev_11_min_empty)
save(mod_dev_11_min_empty, file = "models/mod_dev_11_min_empty.RData")
```


## Calculating ICCs for empty models

```{r}
performance::icc(mod_dev_07_min_empty) # set by_group = TRUE for specific group-levels
performance::icc(mod_dev_11_min_empty)
```

mod_dev_07_min_empty: 0.933
mod_dev_11_min_empty: 0.581


## Analysis of legislators’ deviation in roll call votes from their club vote excluding umbrella organizations

```{r}
# Combined Model 1907-1911
mod_dev_07_min <- glmer(dev_group ~ dev_language +
                          dev_sector + 
                          max_vote_share +
                          dev_ideology +
                          dev_assoc +
                          (1|rcv) +
                          (1|rep_id), 
                        data = dev_analysis_group_min %>% 
                          filter(legislature == 1907), 
                        family = binomial(link = "logit"),
                        control = glmerControl(optimizer = "bobyqa", 
                                               optCtrl = list(maxfun = 2e9)))

summary(mod_dev_07_min)
save(mod_dev_07_min, file = "models/mod_dev_07_min.RData")

# District principal Model 1907-1911
mod_dev_07_dist_min <- glmer(dev_group ~ dev_language +
                               dev_sector +
                               max_vote_share +
                               (1|rcv) +
                               (1|rep_id), 
                             data = dev_analysis_group_min %>% 
                               filter(legislature == 1907), 
                             family = binomial(link = "logit"),
                             control = glmerControl(optimizer = "bobyqa", 
                                                    optCtrl = list(maxfun = 2e9)))

summary(mod_dev_07_dist_min)
save(mod_dev_07_dist_min, file = "models/mod_dev_07_dist_min.RData")

# Ideological heterogeneity Model 1907-1911
mod_dev_07_id_min <- glmer(dev_group ~ dev_ideology +
                             (1|rcv) +
                             (1|rep_id), 
                           data = dev_analysis_group_min %>% 
                             filter(legislature == 1907), 
                           family = binomial(link = "logit"),
                           control = glmerControl(optimizer = "bobyqa", 
                                                  optCtrl = list(maxfun = 2e9)))

summary(mod_dev_07_id_min)
save(mod_dev_07_id_min, file = "models/mod_dev_07_id_min.RData")

# Functional principal Model 1907-1911
mod_dev_07_func_min <- glmer(dev_group ~ dev_assoc +
                               (1|rcv) +
                               (1|rep_id), 
                             data = dev_analysis_group_min %>% 
                               filter(legislature == 1907), 
                             family = binomial(link = "logit"),
                             control = glmerControl(optimizer = "bobyqa", 
                                                    optCtrl = list(maxfun = 2e9)))

summary(mod_dev_07_func_min)
save(mod_dev_07_func_min, file = "models/mod_dev_07_func_min.RData")

# Combined Model 1911-1914
mod_dev_11_min <- glmer(dev_group ~ dev_language +
                          dev_sector + 
                          max_vote_share +
                          dev_ideology +
                          dev_assoc +
                          (1|rcv) +
                          (1|rep_id), 
                        data = dev_analysis_group_min %>% 
                          filter(legislature == 1911), 
                        family = binomial(link = "logit"),
                        control = glmerControl(optimizer = "bobyqa", 
                                               optCtrl = list(maxfun = 2e9)))

summary(mod_dev_11_min)
save(mod_dev_11_min, file = "models/mod_dev_11_min.RData")

# District principal Model 1911-1914
mod_dev_11_dist_min <- glmer(dev_group ~ dev_language +
                               dev_sector +
                               max_vote_share +
                               (1|rcv) +
                               (1|rep_id), 
                             data = dev_analysis_group_min %>% 
                               filter(legislature == 1911), 
                             family = binomial(link = "logit"),
                             control = glmerControl(optimizer = "bobyqa", 
                                                    optCtrl = list(maxfun = 2e9)))

summary(mod_dev_11_dist_min)
save(mod_dev_11_dist_min, file = "models/mod_dev_11_dist_min.RData")

# Ideological heterogeneity Model 1911-1914
mod_dev_11_id_min <- glmer(dev_group ~ dev_ideology +
                             (1|rcv) +
                             (1|rep_id), 
                           data = dev_analysis_group_min %>% 
                             filter(legislature == 1911), 
                           family = binomial(link = "logit"),
                           control = glmerControl(optimizer = "bobyqa", 
                                                  optCtrl = list(maxfun = 2e9)))

summary(mod_dev_11_id_min)
save(mod_dev_11_id_min, file = "models/mod_dev_11_id_min.RData")

# Functional principal Model 1911-1914
mod_dev_11_func_min <- glmer(dev_group ~ dev_assoc +
                               (1|rcv) +
                               (1|rep_id), 
                             data = dev_analysis_group_min %>% 
                               filter(legislature == 1911), 
                             family = binomial(link = "logit"),
                             control = glmerControl(optimizer = "bobyqa", 
                                                    optCtrl = list(maxfun = 2e9)))

summary(mod_dev_11_func_min)
save(mod_dev_11_func_min, file = "models/mod_dev_11_func_min.RData")
```


## Appendix E – Detailed Regression Results, Tables 5 - 6

```{r}
wordreg(l = list(mod_dev_07_dist_min,  mod_dev_07_id_min, 
                 mod_dev_07_func_min, mod_dev_07_min),
        file = "tables/appendix_e_table_5.doc",
        custom.model.names = c("District Principal Model", "Ideological Heterogeneity Model", 
                               "Functional Principal Model", "Combined Model"),
        custom.coef.map = list("dev_language" = "Different National Identity", 
                               "dev_sector" = "Different Economic Sector",
                               "max_vote_share" = "District Competitiveness",
                               "dev_ideology" = "Different Ideology",
                               "dev_assoc" = "Different Association Memberships",
                               "(Intercept)" = "Intercept"),
        groups = list("Fixed Effects \n District Principal" = 1:3, 
                      "Party Ideology" = 4:4, 
                      "Functional Principal" = 5:6),
        custom.gof.names = c(NA, NA, NA, "Number of Observations", 
                             "Number of Legislators", "Number of RCVs", 
                             "Variance Intercept Legislator", "Variance Intercept RCV"),
        custom.gof.rows = list("Random Effects" = c("", "", "", "")),
        reorder.gof = c(1, 9, 8, 2, 3, 4, 7, 6, 5),
        single.row = TRUE)

wordreg(l = list(mod_dev_11_dist_min,  mod_dev_11_id_min, 
                 mod_dev_11_func_min, mod_dev_11_min),
        file = "tables/appendix_e_table_6.doc",
        custom.model.names = c("District Principal Model", "Ideological Heterogeneity Model", 
                               "Functional Principal Model", "Combined Model"),
        custom.coef.map = list("dev_language" = "Different National Identity", 
                               "dev_sector" = "Different Economic Sector",
                               "max_vote_share" = "District Competitiveness",
                               "dev_ideology" = "Different Ideology",
                               "dev_assoc" = "Different Association Memberships",
                               "(Intercept)" = "Intercept"),
        groups = list("Fixed Effects \n District Principal" = 1:3, 
                      "Party Ideology" = 4:4, 
                      "Functional Principal" = 5:6),
        custom.gof.names = c(NA, NA, NA, "Number of Observations", 
                             "Number of Legislators", "Number of RCVs", 
                             "Variance Intercept Legislator", "Variance Intercept RCV"),
        custom.gof.rows = list("Random Effects" = c("", "", "", "")),
        reorder.gof = c(1, 9, 8, 2, 3, 4, 7, 6, 5),
        single.row = TRUE)
```


# Deviation analysis from electoral party

```{r}
load(file = "dev_analysis_party.RData")
```


## Empty models

```{r}
# Empty Model 1907-1911
mod_dev_07_party_empty <- glmer(dev_party ~  
                                  (1|rcv) +
                                  (1|rep_id), 
                                data = dev_analysis_party %>% 
                                  filter(legislature == 1907), 
                                family = binomial(link = "logit"),
                                control = glmerControl(optimizer = "bobyqa", 
                                                       optCtrl = list(maxfun = 2e9)))

summary(mod_dev_07_party_empty)
save(mod_dev_07_party_empty, file = "models/mod_dev_07_party_empty.RData")

# Empty Model 1911-1914
mod_dev_11_party_empty <- glmer(dev_party ~  
                                  (1|rcv) +
                                  (1|rep_id), 
                                data = dev_analysis_party %>% 
                                  filter(legislature == 1911), 
                                family = binomial(link = "logit"),
                                control = glmerControl(optimizer = "bobyqa", 
                                                       optCtrl = list(maxfun = 2e9)))

summary(mod_dev_11_party_empty)
save(mod_dev_11_party_empty, file = "models/mod_dev_11_party_empty.RData")
```


## Calculating ICCs for empty models

```{r}
performance::icc(mod_dev_07_party_empty) # set by_group = TRUE for specific group-levels
performance::icc(mod_dev_11_party_empty)
```

mod_dev_07_party_empty: 0.536
mod_dev_11_party_empty: 0.713


## Analysis of legislators’ deviation in roll call votes from their electoral party vote

```{r}
# Combined Model 1907-1911
mod_dev_07_party <- glmer(dev_party ~ dev_language +
                            dev_sector + 
                            max_vote_share +
                            dev_assoc +
                            (1|rcv) +
                            (1|rep_id), 
                          data = dev_analysis_party %>% 
                            filter(legislature == 1907), 
                          family = binomial(link = "logit"),
                          control = glmerControl(optimizer = "bobyqa", 
                                                 optCtrl = list(maxfun = 2e9)))

summary(mod_dev_07_party)
save(mod_dev_07_party, file = "models/mod_dev_07_party.RData")

# District principal Model 1907-1911
mod_dev_07_dist_party <- glmer(dev_party ~ dev_language +
                                 dev_sector +
                                 max_vote_share +
                                 (1|rcv) +
                                 (1|rep_id), 
                               data = dev_analysis_party %>% 
                                 filter(legislature == 1907), 
                               family = binomial(link = "logit"),
                               control = glmerControl(optimizer = "bobyqa", 
                                                      optCtrl = list(maxfun = 2e9)))

summary(mod_dev_07_dist_party)
save(mod_dev_07_dist_party, file = "models/mod_dev_07_dist_party.RData")

# Functional principal Model 1907-1911
mod_dev_07_func_party <- glmer(dev_party ~ dev_assoc +
                                 (1|rcv) +
                                 (1|rep_id), 
                               data = dev_analysis_party %>% 
                                 filter(legislature == 1907), 
                               family = binomial(link = "logit"),
                               control = glmerControl(optimizer = "bobyqa", 
                                                      optCtrl = list(maxfun = 2e9)))

summary(mod_dev_07_func_party)
save(mod_dev_07_func_party, file = "models/mod_dev_07_func_party.RData")

# Combined Model 1911-1914
mod_dev_11_party <- glmer(dev_party ~ dev_language +
                            dev_sector + 
                            max_vote_share +
                            dev_assoc +
                            (1|rcv) +
                            (1|rep_id), 
                          data = dev_analysis_party %>% 
                            filter(legislature == 1911), 
                          family = binomial(link = "logit"),
                          control = glmerControl(optimizer = "bobyqa", 
                                                 optCtrl = list(maxfun = 2e9)))

summary(mod_dev_11_party)
save(mod_dev_11_party, file = "models/mod_dev_11_party.RData")

# District principal Model 1911-1914
mod_dev_11_dist_party <- glmer(dev_party ~ dev_language +
                                 dev_sector +
                                 max_vote_share +
                                 (1|rcv) +
                                 (1|rep_id), 
                               data = dev_analysis_party %>% 
                                 filter(legislature == 1911), 
                               family = binomial(link = "logit"),
                               control = glmerControl(optimizer = "bobyqa", 
                                                      optCtrl = list(maxfun = 2e9)))

summary(mod_dev_11_dist_party)
save(mod_dev_11_dist_party, file = "models/mod_dev_11_dist_party.RData")

# Functional principal Model 1911-1914
mod_dev_11_func_party <- glmer(dev_party ~ dev_assoc +
                                 (1|rcv) +
                                 (1|rep_id), 
                               data = dev_analysis_party %>% 
                                 filter(legislature == 1911), 
                               family = binomial(link = "logit"),
                               control = glmerControl(optimizer = "bobyqa", 
                                                      optCtrl = list(maxfun = 2e9)))

summary(mod_dev_11_func_party)
save(mod_dev_11_func_party, file = "models/mod_dev_11_func_party.RData")
```


## Appendix E – Detailed Regression Results, Tables 7 - 8

```{r}
wordreg(l = list(mod_dev_07_dist_party, mod_dev_07_func_party, mod_dev_07_party),
        file = "tables/appendix_e_table_7.doc",
        custom.model.names = c("District Principal Model", "Functional Principal Model", 
                               "Combined Model"),
        custom.coef.map = list("dev_language" = "Different National Identity", 
                               "dev_sector" = "Different Economic Sector",
                               "max_vote_share" = "District Competitiveness",
                               "dev_assoc" = "Different Association Memberships",
                               "(Intercept)" = "Intercept"),
        groups = list("Fixed Effects \n District Principal" = 1:3, 
                      "Functional Principal" = 4:5),
        custom.gof.names = c(NA, NA, NA, "Number of Observations", 
                             "Number of Legislators", "Number of RCVs", 
                             "Variance Intercept Legislator", "Variance Intercept RCV"),
        custom.gof.rows = list("Random Effects" = c("", "", "")),
        reorder.gof = c(1, 9, 8, 2, 3, 4, 7, 6, 5),
        single.row = TRUE)

wordreg(l = list(mod_dev_11_dist_party, mod_dev_11_func_party, mod_dev_11_party),
        file = "tables/appendix_e_table_8.doc",
        custom.model.names = c("District Principal Model", "Functional Principal Model",
                               "Combined Model"),
        custom.coef.map = list("dev_language" = "Different National Identity", 
                               "dev_sector" = "Different Economic Sector",
                               "max_vote_share" = "District Competitiveness",
                               "dev_assoc" = "Different Association Memberships",
                               "(Intercept)" = "Intercept"),
        groups = list("Fixed Effects \n District Principal" = 1:3, 
                      "Functional Principal" = 4:5),
        custom.gof.names = c(NA, NA, NA, "Number of Observations", 
                             "Number of Legislators", "Number of RCVs", 
                             "Variance Intercept Legislator", "Variance Intercept RCV"),
        custom.gof.rows = list("Random Effects" = c("", "", "")),
        reorder.gof = c(1, 9, 8, 2, 3, 4, 7, 6, 5),
        single.row = TRUE)
```



# Indices of Agreement

## Figure 3 - Index of Agreement for Parliamentary Clubs and Umbrella Organizations.     

```{r}
load("vote_by_group_max.RData")

cohesion_max <- vote_by_group_max %>% 
  group_by(legislature, klub_no_ind_max) %>% 
  summarise(cohesion = mean(cohesion_wabsent), .groups = "keep") %>% 
  ungroup() %>% 
  mutate(umbrella = case_when(klub_no_ind_max == "bohun" |
                                klub_no_ind_max == "gernatpan" |
                                klub_no_ind_max == "narsve" |
                                klub_no_ind_max == "socdem" |
                                klub_no_ind_max == "uk" |
                                klub_no_ind_max == "unilat" ~ 1,
                              TRUE ~ 0),
         klub_no_ind_max = case_when(klub_no_ind_max == "bohun" ~ "Unified Bohemian Club",
                                     klub_no_ind_max == "catnat" ~ "Catholic National Club",
                                     klub_no_ind_max == "chrsoc" ~ "Christian Social Assoc.",
                                     klub_no_ind_max == "cze" ~ "Czech Club",
                                     klub_no_ind_max == "czeagr" ~ "Czech Agrarians Club",
                                     klub_no_ind_max == "czein" ~ "Assoc. of Ind. &<br> Progressive Bohemians",
                                     klub_no_ind_max == "czenatsoc" ~ "Czech National Social Club",
                                     klub_no_ind_max == "czenatsocradpro" ~ "Org. of Czech Nat. Soc. &<br> Rad. Progressives",
                                     klub_no_ind_max == "czepeo" ~ "Czech Peoples Party",
                                     klub_no_ind_max == "czepro" ~ "Czech Progressive Party",
                                     klub_no_ind_max == "gernatpan" ~ "German National Assoc.",
                                     klub_no_ind_max == "italib" ~ "Liberal Italians Club",
                                     klub_no_ind_max == "itapeo" ~ "Italian Peoples Party",
                                     klub_no_ind_max == "jew" ~ "Jewish Club",
                                     klub_no_ind_max == "narsve" & legislature == 1907 ~ "National Association ",
                                     klub_no_ind_max == "narsve" & legislature == 1911 ~ "Croatian-Slovenian Club",
                                     klub_no_ind_max == "panger" ~ "Pan-German Group",
                                     klub_no_ind_max == "pol" ~ "Polish Club",
                                     klub_no_ind_max == "rom" ~ "Romanian Club",
                                     klub_no_ind_max == "rut" ~ "Ruthenian Club",
                                     klub_no_ind_max == "rutbuk" ~ "Bukovina Ukrainian Klub",
                                     klub_no_ind_max == "slo" & legislature == 1907 ~ "Slovenian Club",
                                     klub_no_ind_max == "slo" & legislature == 1911 ~ "Croatian-Slovenian Association",
                                     klub_no_ind_max == "socdem" ~ "Assoc. of Social Democrats",
                                     klub_no_ind_max == "sousla" & legislature == 1907 ~ "Assoc. of South Slavs",
                                     klub_no_ind_max == "sousla" & legislature == 1911 ~ "Dalmatian Club",
                                     klub_no_ind_max == "uk" ~ "Ukrainian Assoc.",
                                     klub_no_ind_max == "unilat" ~ "Latin Union") %>% 
           as_factor(),
         legislature = case_when(legislature == 1907 ~ "1907 - 1911, 29 RCVs",
                                 legislature == 1911 ~ "1911 - 1914, 41 RCVs"),
         styledlabel = if_else(umbrella == 1, glue("<i>{klub_no_ind_max}</i>"), glue("{klub_no_ind_max}")))

ggplot(cohesion_max, 
       aes(y = tidytext::reorder_within(styledlabel, cohesion, legislature), x = cohesion)) + 
  geom_col() + 
  tidytext::scale_y_reordered() +
  ggforce::facet_col(~ legislature, space = "free", scales = "free_y") +
  xlab("Mean Agreement Index") +
  ylab(element_blank()) +
  labs(caption = "<i>Note:</i> Umbrella organizations in italics.") + 
  theme_bw() + 
  theme(text = element_text(family = "serif"),
        strip.text.x = element_text(size = 12),
        axis.text.y = element_markdown(size = 10),
        axis.title.x = element_text(size = 12),
        plot.caption = element_markdown(size = 10))

ggsave("figures/figure_3.jpeg", width = 20, height = 28, units = "cm", dpi = 800)
```



## Appendix F – Index of Agreement for Parliamentary Clubs without Umbrella Organizations

```{r}
load("data_full.RData")
load("vote_by_group_min.RData")

cohesion_min <- vote_by_group_min %>% 
  group_by(legislature, klub_no_ind_min) %>% 
  summarise(cohesion = mean(cohesion_wabsent, na.rm = TRUE), .groups = "keep") %>% 
  ungroup() %>% 
  mutate(klub_no_ind_min = case_when(klub_no_ind_min == "bohsoc" ~ "Czech Social Democrats Club",
                                     klub_no_ind_min == "bohun" ~ "Unified Bohemian Club",
                                     klub_no_ind_min == "catnat" ~ "Catholic National Club",
                                     klub_no_ind_min == "chrsoc" ~ "Christian Social Assoc.",
                                     klub_no_ind_min == "cze" ~ "Czech Club",
                                     klub_no_ind_min == "czeagr" ~ "Czech Agrarians Club",
                                     klub_no_ind_min == "czein" ~ "Assoc. of Ind. &\n Progressive Bohemians",
                                     klub_no_ind_min == "czenatsoc" ~ "Czech National Social Club",
                                     klub_no_ind_min == "czenatsocradpro" ~ "Org. of Czech Nat. Soc. &\n Rad. Progressives",
                                     klub_no_ind_min == "czepeo" ~ "Czech Peoples Party",
                                     klub_no_ind_min == "czepro" ~ "Czech Progressive Party",
                                     klub_no_ind_min == "geragr" ~ "Group of the German Agrarian Party",
                                     klub_no_ind_min == "gerlab" ~ "Group of the German Labor Party",
                                     klub_no_ind_min == "gernat" ~ "German National Assoc. (Party)",
                                     klub_no_ind_min == "gernatpan" ~ "German National Assoc.",
                                     klub_no_ind_min == "gerpro" ~ "German Progressive Assoc.",
                                     klub_no_ind_min == "gerrad" ~ "German Radical Assoc.",
                                     klub_no_ind_min == "gersoc" ~ "German Social Democrats Club",
                                     klub_no_ind_min == "geryou" ~ "Young German Association",
                                     klub_no_ind_min == "italib" ~ "Liberal Italians Club",
                                     klub_no_ind_min == "itapeo" ~ "Italian Peoples Party",
                                     klub_no_ind_min == "itasoc" ~ "Italian Social Democrats Group",
                                     klub_no_ind_min == "jew" ~ "Jewish Club",
                                     klub_no_ind_min == "nat" ~ "National Club",
                                     klub_no_ind_min == "panger" ~ "Pan-German Group",
                                     klub_no_ind_min == "pol" ~ "Polish Club",
                                     klub_no_ind_min == "posoc" ~ "Polish Social Democrats Club ",
                                     klub_no_ind_min == "rom" ~ "Romanian Club",
                                     klub_no_ind_min == "rut" ~ "Ruthenian Club",
                                     klub_no_ind_min == "rutbuk" ~ "Bukovina Ukrainian Klub",
                                     klub_no_ind_min == "slo" & legislature == 1907 ~ "Slovenian Club",
                                     klub_no_ind_min == "slo" & legislature == 1911 ~ "Croatian-Slovenian Association",
                                     klub_no_ind_min == "socdem" ~ "Assoc. of Social Democrats",
                                     klub_no_ind_min == "sousla" & legislature == 1907 ~ "Assoc. of South Slavs",
                                     klub_no_ind_min == "sousla" & legislature == 1911 ~ "Dalmatian Club",
                                     klub_no_ind_min == "uk" ~ "Ukrainian Assoc.") %>% 
           as_factor(),
         legislature = case_when(legislature == 1907 ~ "1907 - 1911, 29 RCVs",
                                 legislature == 1911 ~ "1911 - 1914, 41 RCVs"))

ggplot(cohesion_min, 
       aes(y = tidytext::reorder_within(klub_no_ind_min, cohesion, legislature), x = cohesion)) + 
  geom_col() + 
  tidytext::scale_y_reordered() +
  ggforce::facet_col(~ legislature, space = "free", scales = "free_y") +
  xlab("Mean Agreement Index") +
  ylab(element_blank()) +
  theme_bw() + 
  theme(text = element_text(family = "serif"),
        strip.text.x = element_text(size = 12),
        axis.text.y = element_text(size = 10),
        axis.title.x = element_text(size = 12))

ggsave("figures/figure_appendix_f.jpeg", width = 20, height = 28, units = "cm", dpi = 800)
```


## Appendix G – Index of Agreement for Electoral Parties

```{r}
load("vote_by_party.RData")

party_labels_1907 <- read_excel("data/party_labels.xlsx", 
                                sheet = "1907") %>% 
  mutate(legislature = 1907)

party_labels_1911 <- read_excel("data/party_labels.xlsx", 
                                sheet = "1911") %>% 
  mutate(legislature = 1911)

party_labels <- bind_rows(party_labels_1907, party_labels_1911)

cohesion_party <- vote_by_party %>% 
  left_join(party_labels %>% select(partylabel, partyname, legislature), 
            by = c("partylabel_no_ind" = "partylabel", "legislature")) %>% 
  group_by(legislature, partyname) %>% 
  summarise(cohesion = mean(cohesion_wabsent, na.rm = TRUE), .groups = "keep") %>% 
  ungroup() %>% 
  mutate(legislature = case_when(legislature == 1907 ~ "1907 - 1911, 29 RCVs",
                                 legislature == 1911 ~ "1911 - 1914, 41 RCVs"))

ggplot(cohesion_party, 
       aes(y = tidytext::reorder_within(partyname, cohesion, legislature), x = cohesion)) + 
  geom_col() + 
  tidytext::scale_y_reordered() +
  ggforce::facet_col(~ legislature, space = "free", scales = "free_y") +
  xlab("Mean Agreement Index") +
  ylab(element_blank()) +
  theme_bw() + 
  theme(text = element_text(family = "serif"),
        strip.text.x = element_text(size = 12),
        axis.text.y = element_text(size = 10),
        axis.title.x = element_text(size = 12))

ggsave("figures/figure_appendix_g.jpeg", width = 20, height = 28, units = "cm", dpi = 800)
```


## Appendix H - Index of Agreement of major clubs by policy area.

```{r}
#load("vote_by_group_max.RData") uncomment if dataset was not loaded in previous code chunk

rcv_issues <- data_full %>% 
  select(rcv, issue_area) %>% 
  distinct()

cohesion_issue_max <- vote_by_group_max %>% 
  left_join(rcv_issues, by = "rcv") %>% 
  group_by(legislature, issue_area, klub_no_ind_max) %>% 
  summarise(cohesion = mean(cohesion_wabsent), .groups = "keep") %>% 
  ungroup() %>% 
  mutate(klub_no_ind_max = case_when(klub_no_ind_max == "bohun" ~ "Czech Club /\n Unified Bohemian Club",
                                     klub_no_ind_max == "catnat" ~ "Catholic National Club",
                                     klub_no_ind_max == "chrsoc" ~ "Christian Social Assoc.",
                                     klub_no_ind_max == "cze" ~ "Czech Club /\n Unified Bohemian Club",
                                     klub_no_ind_max == "czeagr" ~ "Czech Agrarians Club /\n Unified Bohemian Club",
                                     klub_no_ind_max == "czein" ~ "Assoc. of Ind. &\n Progressive Bohemians",
                                     klub_no_ind_max == "czenatsoc" ~ "Czech National Social Club",
                                     klub_no_ind_max == "czenatsocradpro" ~ "Org. of Czech Nat. Soc. &\n Rad. Progressives",
                                     klub_no_ind_max == "czepeo" ~ "Czech Peoples Party",
                                     klub_no_ind_max == "czepro" ~ "Czech Progressive Party",
                                     klub_no_ind_max == "gernatpan" ~ "German National Assoc.",
                                     klub_no_ind_max == "italib" ~ "Liberal Italians Club",
                                     klub_no_ind_max == "itapeo" ~ "Italian Peoples Party",
                                     klub_no_ind_max == "jew" ~ "Jewish Club",
                                     klub_no_ind_max == "narsve" & legislature == 1907 ~ "National Association ",
                                     klub_no_ind_max == "narsve" & legislature == 1911 ~ "Croatian-Slovenian Club",
                                     klub_no_ind_max == "panger" ~ "Pan-German Group",
                                     klub_no_ind_max == "pol" ~ "Polish Club",
                                     klub_no_ind_max == "rom" ~ "Romanian Club",
                                     klub_no_ind_max == "rut" ~ "Ruthenian Club",
                                     klub_no_ind_max == "rutbuk" ~ "Bukovina Ukrainian Klub",
                                     klub_no_ind_max == "slo" & legislature == 1907 ~ "Slovenian Club",
                                     klub_no_ind_max == "slo" & legislature == 1911 ~ "Croatian-Slovenian Association",
                                     klub_no_ind_max == "socdem" ~ "Assoc. of Social Democrats",
                                     klub_no_ind_max == "sousla" & legislature == 1907 ~ "Assoc. of South Slavs",
                                     klub_no_ind_max == "sousla" & legislature == 1911 ~ "Dalmatian Club",
                                     klub_no_ind_max == "uk" ~ "Ukrainian Assoc.",
                                     klub_no_ind_max == "unilat" ~ "Latin Union") %>% 
           as_factor(),
         legislature = case_when(legislature == 1907 ~ "1907 - 1911, 29 RCVs",
                                 legislature == 1911 ~ "1911 - 1914, 41 RCVs"),
         issue_area = issue_area %>% str_to_title())

bohun <- cohesion_issue_max %>% 
  filter(legislature == "1911 - 1914, 41 RCVs",
         klub_no_ind_max == "Czech Club /\n Unified Bohemian Club") %>% 
  mutate(klub_no_ind_max = "Czech Agrarians Club /\n Unified Bohemian Club")

ggplot(cohesion_issue_max %>% 
         bind_rows(bohun) %>% 
         filter(issue_area != "Religion And Morality",
                klub_no_ind_max == "Christian Social Assoc." |
                  klub_no_ind_max == "Czech Club /\n Unified Bohemian Club" |
                  klub_no_ind_max == "Czech Agrarians Club /\n Unified Bohemian Club" |
                  klub_no_ind_max == "German National Assoc." |
                  klub_no_ind_max == "Polish Club" |
                  klub_no_ind_max == "Assoc. of Social Democrats"), 
       aes(y = reorder(issue_area, desc(issue_area)), x = cohesion)) + 
  geom_col() + 
  facet_grid(klub_no_ind_max ~ legislature, scales = "free_y") +
  xlab("Mean Agreement Index") +
  ylab(element_blank()) +
  labs(caption = "<i>Note:</i> No roll call votes on the issue of nationalities in the second term (1911-1914).
       The issue religion and morality is not displayed, as there was just one roll call vote.
       The Czech Club and the Czech Agrarian Club both joined the Unified Bohemian Club in the second term.") +
  theme_bw() + 
  theme(text = element_text(family = "serif"),
        strip.text.x = element_text(size = 12),
        axis.text.y = element_text(size = 10),
        axis.title.x = element_text(size = 12),
        plot.caption = element_textbox_simple(size = 10, width = unit(1, "npc"), 
                                              margin = margin(10, 10, 10, 10)))

ggsave("figures/figure_appendix_h.jpeg", width = 20, height = 28, units = "cm", dpi = 800)
```


# Appendix A – Parliamentary Clubs, Umbrella Organizations and Electoral Party Labels

```{r}
#load("data_full.RData") uncomment if dataset was not loaded in previous code chunk

party_labels_1907 <- read_excel("data/party_labels.xlsx", 
                                sheet = "1907")

label_dist <- data_full %>% 
  filter(!is.na(klub_no_ind_max)) %>% 
  select(session_detailed, rep_id, klub_no_ind_max, 
         klub_no_ind_min, partylabel) %>% 
  distinct() %>% 
  add_count(session_detailed, klub_no_ind_max, name = "n_umbrella") %>% 
  add_count(session_detailed, klub_no_ind_max, klub_no_ind_min, name = "n_club") %>% 
  add_count(session_detailed, klub_no_ind_max, klub_no_ind_min, partylabel, name = "n_party") %>% 
  select(-rep_id) %>% 
  distinct() %>% 
  mutate(share_max = n_party/n_umbrella * 100) %>% 
  pivot_wider(names_from = session_detailed,
              values_from = 5:8)

vis_label_dist_181 <- label_dist %>% 
  select(klub_no_ind_max, klub_no_ind_min, partylabel, n_party_181, share_max_181) %>% 
  filter(!is.na(n_party_181)) %>% 
  arrange(klub_no_ind_max) %>% 
  mutate(klub_no_ind_max = case_when(klub_no_ind_max == "bohun" ~ "Unified Bohemian Club",
                                     klub_no_ind_max == "catnat" ~ "Catholic National Club",
                                     klub_no_ind_max == "chrsoc" ~ "Christian Social Assoc.",
                                     klub_no_ind_max == "cze" ~ "Czech Club",
                                     klub_no_ind_max == "czeagr" ~ "Czech Agrarians Club",
                                     klub_no_ind_max == "czein" ~ "Assoc. of Ind. &\n Progressive Bohemians",
                                     klub_no_ind_max == "czenatsoc" ~ "Czech National Social Club",
                                     klub_no_ind_max == "czenatsocradpro" ~ "Org. of Czech Nat. Soc. &\n Rad. Progressives",
                                     klub_no_ind_max == "czepeo" ~ "Czech Peoples Party",
                                     klub_no_ind_max == "czepro" ~ "Czech Progressive Party",
                                     klub_no_ind_max == "gernatpan" ~ "German National Assoc.",
                                     klub_no_ind_max == "italib" ~ "Liberal Italians Club",
                                     klub_no_ind_max == "itapeo" ~ "Italian Peoples Party",
                                     klub_no_ind_max == "jew" ~ "Jewish Club",
                                     klub_no_ind_max == "narsve" ~ "National Association",
                                     klub_no_ind_max == "panger" ~ "Pan-German Group",
                                     klub_no_ind_max == "pol" ~ "Polish Club",
                                     klub_no_ind_max == "rom" ~ "Romanian Club",
                                     klub_no_ind_max == "rut" ~ "Ruthenian Club",
                                     klub_no_ind_max == "rutbuk" ~ "Bukovina Ukrainian Klub",
                                     klub_no_ind_max == "slo" ~ "Slovenian Club",
                                     klub_no_ind_max == "socdem" ~ "Assoc. of Social Democrats",
                                     klub_no_ind_max == "sousla" ~ "Assoc. of South Slavs",
                                     klub_no_ind_max == "uk" ~ "Ukrainian Assoc.",
                                     klub_no_ind_max == "unilat" ~ "Latin Union"),
         klub_no_ind_min = case_when(klub_no_ind_min == "bohsoc" ~ "Czech Social Democrats Club",
                                     klub_no_ind_min == "bohun" ~ "Unified Bohemian Club",
                                     klub_no_ind_min == "catnat" ~ "Catholic National Club",
                                     klub_no_ind_min == "chrsoc" ~ "Christian Social Assoc.",
                                     klub_no_ind_min == "cze" ~ "Czech Club",
                                     klub_no_ind_min == "czeagr" ~ "Czech Agrarians Club",
                                     klub_no_ind_min == "czein" ~ "Assoc. of Ind. &\n Progressive Bohemians",
                                     klub_no_ind_min == "czenatsoc" ~ "Czech National Social Club",
                                     klub_no_ind_min == "czenatsocradpro" ~ "Org. of Czech Nat. Soc. &\n Rad. Progressives",
                                     klub_no_ind_min == "czepeo" ~ "Czech Peoples Party",
                                     klub_no_ind_min == "czepro" ~ "Czech Progressive Party",
                                     klub_no_ind_min == "geragr" ~ "Group of the German Agrarian Party",
                                     klub_no_ind_min == "gerlab" ~ "Group of the German Labor Party",
                                     klub_no_ind_min == "gernat" ~ "German National Assoc.",
                                     klub_no_ind_min == "gernatpan" ~ "German National Assoc.",
                                     klub_no_ind_min == "gerpro" ~ "German Progressive Assoc.",
                                     klub_no_ind_min == "gerrad" ~ "German Radical Assoc.",
                                     klub_no_ind_min == "gersoc" ~ "German Social Democrats Club",
                                     klub_no_ind_min == "geryou" ~ "Young German Association",
                                     klub_no_ind_min == "italib" ~ "Liberal Italians Club",
                                     klub_no_ind_min == "itapeo" ~ "Italian Peoples Party",
                                     klub_no_ind_min == "itasoc" ~ "Italian Social Democrats Group",
                                     klub_no_ind_min == "jew" ~ "Jewish Club",
                                     klub_no_ind_min == "nat" ~ "National Club",
                                     klub_no_ind_min == "panger" ~ "Pan-German Group",
                                     klub_no_ind_min == "pol" ~ "Polish Club",
                                     klub_no_ind_min == "posoc" ~ "Polish Social Democrats Club ",
                                     klub_no_ind_min == "rom" ~ "Romanian Club",
                                     klub_no_ind_min == "rut" ~ "Ruthenian Club",
                                     klub_no_ind_min == "rutbuk" ~ "Bukovina Ukrainian Klub",
                                     klub_no_ind_min == "slo" ~ "Slovenian Club",
                                     klub_no_ind_min == "socdem" ~ "Assoc. of Social Democrats",
                                     klub_no_ind_min == "sousla" ~ "Assoc. of South Slavs",
                                     klub_no_ind_min == "uk" ~ "Ukrainian Assoc.")) %>% 
  left_join(party_labels_1907 %>% select(partylabel, partyname), by = "partylabel") %>% 
  select(klub_no_ind_max, klub_no_ind_min, partyname, n_party_181, share_max_181) %>% 
  arrange(klub_no_ind_max, klub_no_ind_min, partyname)

sjPlot::tab_df(vis_label_dist_181, file = "tables/appendix_a_table_1.doc")

party_labels_1911 <- read_excel("data/party_labels.xlsx", 
                                sheet = "1911")

vis_label_dist_211 <- label_dist %>% 
  select(klub_no_ind_max, klub_no_ind_min, partylabel, n_party_211, share_max_211) %>% 
  filter(!is.na(n_party_211)) %>% 
  arrange(klub_no_ind_max) %>% 
  mutate(klub_no_ind_max = case_when(klub_no_ind_max == "bohun" ~ "Unified Bohemian Club",
                                     klub_no_ind_max == "chrsoc" ~ "Christian Social Assoc.",
                                     klub_no_ind_max == "gernatpan" ~ "German National Assoc.",
                                     klub_no_ind_max == "narsve" ~ "Croatian-Slovenian Club",
                                     klub_no_ind_max == "pol" ~ "Polish Club",
                                     klub_no_ind_max == "socdem" ~ "Assoc. of Social Democrats",
                                     klub_no_ind_max == "sousla" ~ "Dalmatian Club",
                                     klub_no_ind_max == "uk" ~ "Ukrainian Assoc.",
                                     klub_no_ind_max == "unilat" ~ "Latin Union"),
         klub_no_ind_min = case_when(klub_no_ind_min == "bohsoc" ~ "Czech Social Democrats Club",
                                     klub_no_ind_min == "bohun" ~ "Unified Bohemian Club",
                                     klub_no_ind_min == "catnat" ~ "Catholic National Club",
                                     klub_no_ind_min == "chrsoc" ~ "Christian Social Assoc.",
                                     klub_no_ind_min == "cze" ~ "Czech Club",
                                     klub_no_ind_min == "czeagr" ~ "Czech Agrarians Club",
                                     klub_no_ind_min == "czein" ~ "Assoc. of Ind. &\n Progressive Bohemians",
                                     klub_no_ind_min == "czenatsoc" ~ "Czech National Social Club",
                                     klub_no_ind_min == "geragr" ~ "Group of the German Agrarian Party",
                                     klub_no_ind_min == "gerlab" ~ "Group of the German Labor Party",
                                     klub_no_ind_min == "gernatpan" ~ "German National Assoc.",
                                     klub_no_ind_min == "gerrad" ~ "German Radical Assoc.",
                                     klub_no_ind_min == "gersoc" ~ "German Social Democrats Club",
                                     klub_no_ind_min == "italib" ~ "Liberal Italians Club",
                                     klub_no_ind_min == "itapeo" ~ "Italian Peoples Party",
                                     klub_no_ind_min == "nat" ~ "National Club",
                                     klub_no_ind_min == "pol" ~ "Polish Club",
                                     klub_no_ind_min == "posoc" ~ "Polish Social Democrats Club ",
                                     klub_no_ind_min == "rom" ~ "Romanian Club",
                                     klub_no_ind_min == "rutbuk" ~ "Bukovina Ukrainian Klub",
                                     klub_no_ind_min == "slo" ~ "Croatian-Slovenian Association",
                                     klub_no_ind_min == "sousla" ~ "Dalmatian Club",
                                     klub_no_ind_min == "uk" ~ "Ukrainian Assoc.")) %>% 
  left_join(party_labels_1911 %>% select(partylabel, partyname), by = "partylabel") %>% 
  select(klub_no_ind_max, klub_no_ind_min, partyname, n_party_211, share_max_211) %>% 
  arrange(klub_no_ind_max, klub_no_ind_min, partyname)

sjPlot::tab_df(vis_label_dist_211, file = "tables/appendix_a_table_2.doc")
```


# Appendix B – Parliamentary Associations and Clubs

```{r}
#load("data_full.RData") uncomment if dataset was not loaded in previous code chunk

assoc_club_dist <- data_full %>% 
  filter(!is.na(klub_no_ind_max)) %>% 
  select(session_detailed, rep_id, klub_no_ind_max, starts_with("v_")) %>% 
  distinct() %>% 
  add_count(session_detailed, klub_no_ind_max, name = "n_umbrella") %>% 
  group_by(session_detailed, klub_no_ind_max) %>% 
  mutate(n_lawyer = sum(v_lawyer, na.rm = TRUE),
         n_agrarian = sum(v_agrarian, na.rm = TRUE), 
         n_commerce = sum(v_commerce, na.rm = TRUE), 
         n_industry = sum(v_industry, na.rm = TRUE), 
         n_resort = sum(v_resort, na.rm = TRUE), 
         n_gerworker = sum(v_gerworker, na.rm = TRUE), 
         n_judge = sum(v_judge, na.rm = TRUE), 
         n_civser = sum(v_civser, na.rm = TRUE), 
         n_technician = sum(v_technician, na.rm = TRUE), 
         n_doctor = sum(v_doctor, na.rm = TRUE), 
         n_markets = sum(v_markets, na.rm = TRUE), 
         n_chrisworker = sum(v_chrisworker, na.rm = TRUE), 
         n_priest = sum(v_priest, na.rm = TRUE), 
         n_teachermid = sum(v_teachermid, na.rm = TRUE), 
         n_monument = sum(v_monument, na.rm = TRUE), 
         n_prof = sum(v_prof, na.rm = TRUE), 
         n_teacher = sum(v_teacher, na.rm = TRUE)) %>%  
  select(-c(rep_id, starts_with("v_"))) %>% 
  distinct() %>% 
  mutate(share_lawyer = n_lawyer/n_umbrella * 100,
         share_agrarian = n_agrarian/n_umbrella * 100,
         share_commerce = n_commerce/n_umbrella * 100,
         share_industry = n_industry/n_umbrella * 100,
         share_resort = n_resort/n_umbrella * 100,
         share_gerworker = n_gerworker/n_umbrella * 100,
         share_judge = n_judge/n_umbrella * 100,
         share_civser = n_civser/n_umbrella * 100,
         share_technician = n_technician/n_umbrella * 100,
         share_doctor = n_doctor/n_umbrella * 100,
         share_markets = n_markets/n_umbrella * 100,
         share_chrisworker = n_chrisworker/n_umbrella * 100,
         share_priest = n_priest/n_umbrella * 100,
         share_teachermid = n_teachermid/n_umbrella * 100,
         share_monument = n_monument/n_umbrella * 100,
         share_prof = n_prof/n_umbrella * 100,
         share_teacher = n_teacher/n_umbrella * 100) %>% #arrange(session_detailed)
  pivot_wider(names_from = session_detailed,
              values_from = 3:37)

assoc_club_dist_181 <- assoc_club_dist %>% 
  select(klub_no_ind_max, ends_with("_181")) %>% 
  drop_na() %>% 
  arrange(klub_no_ind_max) %>% 
  mutate(klub_no_ind_max = case_when(klub_no_ind_max == "catnat" ~ "Catholic National Club",
                                     klub_no_ind_max == "chrsoc" ~ "Christian Social Assoc.",
                                     klub_no_ind_max == "cze" ~ "Czech Club",
                                     klub_no_ind_max == "czeagr" ~ "Czech Agrarians Club",
                                     klub_no_ind_max == "czenatsocradpro" ~ "Org. of Czech Nat. Soc. &\n Rad. Progressives",
                                     klub_no_ind_max == "gernatpan" ~ "German National Assoc.",
                                     klub_no_ind_max == "italib" ~ "Liberal Italians Club",
                                     klub_no_ind_max == "itapeo" ~ "Italian Peoples Party",
                                     klub_no_ind_max == "jew" ~ "Jewish Club",
                                     klub_no_ind_max == "panger" ~ "Pan-German Group",
                                     klub_no_ind_max == "pol" ~ "Polish Club",
                                     klub_no_ind_max == "rom" ~ "Romanian Club",
                                     klub_no_ind_max == "rut" ~ "Ruthenian Club",
                                     klub_no_ind_max == "slo" ~ "Slovenian Club",
                                     klub_no_ind_max == "socdem" ~ "Assoc. of Social Democrats",
                                     klub_no_ind_max == "sousla" ~ "Assoc. of South Slavs")) %>% 
  select(klub_no_ind_max, n_umbrella_181, contains("lawyer"), contains("agrarian"), contains("commerce"),
         contains("industry"), contains("resort"), contains("gerworker"), contains("judge"))

sjPlot::tab_df(assoc_club_dist_181, file = "tables/appendix_b_table_1.doc")


assoc_club_dist_211 <- assoc_club_dist %>% 
  select(klub_no_ind_max, ends_with("_211")) %>% 
  drop_na() %>% 
  arrange(klub_no_ind_max) %>% 
  mutate(klub_no_ind_max = case_when(klub_no_ind_max == "bohun" ~ "Unified Bohemian Club",
                                     klub_no_ind_max == "chrsoc" ~ "Christian Social Assoc.",
                                     klub_no_ind_max == "gernatpan" ~ "German National Assoc.",
                                     klub_no_ind_max == "narsve" ~ "Croatian-Slovenian Club",
                                     klub_no_ind_max == "pol" ~ "Polish Club",
                                     klub_no_ind_max == "socdem" ~ "Assoc. of Social Democrats",
                                     klub_no_ind_max == "sousla" ~ "Dalmatian Club",
                                     klub_no_ind_max == "uk" ~ "Ukrainian Assoc.",
                                     klub_no_ind_max == "unilat" ~ "Latin Union")) %>% 
  select(klub_no_ind_max, n_umbrella_211, contains("lawyer"), contains("commerce"), contains("technician"), 
         contains("doctor"), contains("priest"))

sjPlot::tab_df(assoc_club_dist_211, file = "tables/appendix_b_table_2.doc")
```


# Appendix C – List of Roll Call Votes and Coding of their Issue Area, 1907-1914

```{r}
rcv_issue_coding <- read_excel("data/roll_call_votes.xlsx", 
                               sheet = "codebook", n_max = 211) %>% 
  select(2:6) %>% 
  drop_na() %>% 
  clean_names() %>% 
  mutate(issue_area = issue_area %>% str_to_title(),
         issue = issue %>% str_to_title()) 

sjPlot::tab_df(rcv_issue_coding, file = "tables/appendix_c_table_1.doc")
```


# Appendix D – Classifying electoral parties into ideological camps

```{r}
party_labels_1907 <- read_excel("data/party_labels.xlsx", 
                                sheet = "1907") %>% 
  select(partylabel:basis) %>% 
  arrange(partylabel) %>% 
  filter(partylabel %in% unique(data_full$partylabel))

sjPlot::tab_df(party_labels_1907, file = "tables/appendix_d_table_1.doc")


party_labels_1911 <- read_excel("data/party_labels.xlsx", 
                                sheet = "1911") %>% 
  select(partylabel:basis) %>% 
  arrange(partylabel) %>% 
  filter(partylabel %in% unique(data_full$partylabel))

sjPlot::tab_df(party_labels_1911, file = "tables/appendix_d_table_2.doc")
```

